from flask import Blueprint, request, jsonify, current_app
import logging, os, json
from utils import common
order_bp = Blueprint('order', __name__, url_prefix='/order')

@order_bp.route('/list', methods=['POST'])
def order_list():
    #获取用户支付成功的订单列表
    params = request.json
    data =  current_app.config['DB'].get_order_list(params)
    print(data)
    rv = list()
    for item in data:
        rv.append({
            'order_no':item[0],
            'remark': json.loads(item[1]),
            'paytime':item[2]
        })
    
    return jsonify({'code':0, 'items':rv, 'total':len(rv), 'page':params.get('page'), 'page_size':params.get('page_size')})


@order_bp.record
def log(app):
    logging.info('register order blueprint')
